import { defineStore } from 'pinia'

export const useWebsiteStore = defineStore('websiteStore', {
    state: () => ({
        gameClassify: [],//游戏分类
        gameCollection: [],//游戏合集
        menuList: [
            { id: '', name: '首页', path: '/' },
            { id: '', name: '游戏', path: '/game' },
            { id: '', name: '软件', path: '/software' },
            { id: '', name: '文章', path: '/article' },
            { id: '', name: '合集', path: '/collection' },
            { id: '', name: '排行榜', path: '/ranking' },
            { id: '', name: 'H5游戏', path: '/h5game' },
        ],//菜单列表
    }),
    actions: {
        //获取顶部菜单
        async getMenu() {
            const { $api, $used } = useNuxtApp()
            $api.getMenu().then(res => {
                let list = res.data;
                this.menuList.forEach(item => {
                    list.forEach(item2 => {
                        if (item.name == item2.name) {
                            Object.assign(item, item2);
                        }
                    })
                })
            })
        },
        //获取顶部菜单信息
        async getgetMenuInfo(name) {
            let obj = {};
            //没有id去获取
            if (!this.menuList[0].id) {
                await this.getMenu();
            }
            console.log(this.menuList);
            this.menuList.forEach(item => {
                if (item.name == name) {
                    console.log(item);
                    obj = item;
                }
            })
            console.log(obj);
            return obj;
        },
        //获取游戏列表分类
        async gameTag(params) {
            const { $api, $used } = useNuxtApp()
            let res = await $api.gameTag(params)
            let tag = res.data;
            tag.unshift({ id: 0, name: '全部游戏' })
            this.gameClassify = tag;
            this.gameCollection = res.data.collection;
        }
    }
})
